<template>
    <div>
    <el-checkbox-group v-model="checkedPosition">
        <el-checkbox v-for="pos in posOptions" :label="pos.id" :key="pos.id">{{pos.name}}</el-checkbox>
    </el-checkbox-group>
    <p><span><small style="color: red;">注:带*的推荐位只有被主站设置的文章才会生效</small></span></p>
    </div>

</template>
<script>
    import axios from "axios";
    const posOptions = [
    ];
    export default {
        name: 'AddRowRec',
        props: {
            selectedPosition: {
                type: Array,
                required: false,
                default:function(){
                    return []
                }
            }
        },
        data() {
            return {
                checkedPosition: [],
                posOptions: posOptions
            };
        },
        created() {
            axios.get(this.$api._getPosPosition).then(res => {
                let options = res.body
                let siteId = localStorage.getItem('_site_id_param')
                let computed = []
                if(siteId !='1'){
                    for(let idx in options){
                        if(options[idx].name.indexOf('*') == -1){
                            computed.push(options[idx])
                        }
                    }
                    console.log(computed)
                    this.posOptions = computed
                }else{
                    this.posOptions = options
                }

                //alert(JSON.stringify(this.selectedPosition))
                if (this.selectedPosition.length > 0) {
                    this.checkedPosition = this.selectedPosition.map(x=>parseInt(x)).filter(x=>x);
                }
            })
        },
        watch: {
            'checkedPosition': {
                deep:true,
                handler(val){
                    this.$emit('dataPositionChange', val)
                }
            }
        },
        methods:{
            getPosOptions(){
                axios.get(this.$api._getPosPosition).then(res => {
                    this.posOptions = res.data
                })
            }
        }
    };
</script>